# 数据库配置文件
import os
from typing import Dict, Any
from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

# 数据库类型配置
DATABASE_CONFIGS = {
    # SQLite 配置（默认）
    "sqlite": {
        "type": "sqlite",
        "path": os.path.join(os.path.dirname(__file__), "arbitration.db")
    },
    
    # MySQL 配置
    "mysql": {
        "type": "mysql",
        "host": os.getenv("MYSQL_HOST", "localhost"),
        "port": int(os.getenv("MYSQL_PORT", "3306")),
        "database": os.getenv("MYSQL_DATABASE", "arbitration"),
        "username": os.getenv("MYSQL_USERNAME", "root"),
        "password": os.getenv("MYSQL_PASSWORD", ""),
        "charset": "utf8mb4"
    },
    
    # PostgreSQL 配置
    "postgresql": {
        "type": "postgresql",
        "host": os.getenv("POSTGRES_HOST", "localhost"),
        "port": int(os.getenv("POSTGRES_PORT", "5432")),
        "database": os.getenv("POSTGRES_DATABASE", "arbitration"),
        "username": os.getenv("POSTGRES_USERNAME", "postgres"),
        "password": os.getenv("POSTGRES_PASSWORD", ""),
        "sslmode": os.getenv("POSTGRES_SSLMODE", "prefer")
    },
    
    # 自定义数据库配置
    "custom": {
        "type": os.getenv("DB_TYPE", "sqlite"),
        "connection_string": os.getenv("DATABASE_URL", ""),
        "host": os.getenv("DB_HOST", "localhost"),
        "port": int(os.getenv("DB_PORT", "5432")),
        "database": os.getenv("DB_NAME", "arbitration"),
        "username": os.getenv("DB_USERNAME", ""),
        "password": os.getenv("DB_PASSWORD", "")
    }
}

# 当前使用的数据库配置
CURRENT_DB_TYPE = os.getenv("DATABASE_TYPE", "sqlite")
CURRENT_DB_CONFIG = DATABASE_CONFIGS.get(CURRENT_DB_TYPE, DATABASE_CONFIGS["sqlite"])

# 加密配置
ENCRYPTION_KEY_FILE = os.path.join(os.path.dirname(__file__), "encryption.key")
